/* Joyce
	Event NPC
*/

var status = -1;
var maps = Array(680000000, 230000000, 260000000, 101000000, 211000000, 110000000, 130000200, 100000000, 103000000, 222000000, 240000000, 104000000, 220000000, 800000000, 802000101, 120000000, 600000000, 221000000, 200000000, 102000000, 300000000, 801000000, 540000000, 541000000, 105040300, 250000000, 251000000
    , 551000000, 550000000, 800040000, 261000000, 541020000, 270000000, 229000000, 700000000, 700000100, 700000200, 701000000, 500000000, 680000210, 680000300, 680000400, 740000000, 741000000);
var selectedMap = -1;
var goMap = false;

function start() {
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == 1) {
	status++;
    } else {
	if (status >= 2 || status == 0) {
	    cm.dispose();
	    return;
	}
	status--;
    }

    if (status == 0) {
	//	cm.sendSimple("Hello #r#h ##k! My name is #rJoyce#k. \r\n#b#L0#I want a set of Pink Bean costume!#l \r\n#b#L1#Secret Scroll [4th Job] for 10 million mesos#l \r\n#b#L2#I want to max my 4th Job Skill#l \r\n#b#L3#I would like to learn #bMaker Skill#k#l \r\n#b#L4#Gold and silver keys..#l \r\n#b#L5#I want to go somewhere#l");
	cm.sendSimple("Hello #r#h ##k! My name is #rJoyce#k. \r\n#b#L0#Pink Bean costume...#l \r\n#b#L1#Secret Scroll [4th Job] for 10 million mesos#l \r\n#b#L2#I would like to learn #bMaker Skill#k#l \r\n#b#L3#I want to go somewhere#l");
    } else if (status == 1) {
	if (selection == 0) {
	    if (!cm.haveItem(1052198, 1, true, true)) {
		cm.gainItem(1052198, 1);
	    }
	    if (!cm.haveItem(1102213, 1, true, true)) {
		cm.gainItem(1102213, 1);
	    }
	    if (!cm.haveItem(1002957, 1, true, true)) {
		cm.gainItem(1002957, 1);
	    }
	    cm.dispose();
	} else if (selection == 1) {
	    if (cm.haveItem(4031348)) {
		cm.sendOk("You already have one, I don't think you'll need it anyway.");
	    } else if (cm.getPlayerStat("LVL") >= 120 && cm.getPlayerStat("LVL") <= 130 && cm.getMeso() >= 10000000) {
		if (!cm.canHold(4031348)) {
		    cm.sendOk("Please check if you have sufficient space.");
		} else {
		    cm.gainMeso(-10000000);
		    cm.gainItem(4031348, 1);
		}
	    } else {
		cm.sendOk("Hey, I dont think you have enough mesos or the required level range of 120 ~ 130.");
	    }
	    cm.dispose();
	/*	} else if (selection == 2) {
	    switch (cm.getJob()) {
		case 112:
		    cm.teachSkill(1120004,30,30); //Achilles
		    cm.teachSkill(1120003,30,30); //Advanced Combo
		    cm.teachSkill(1120005,30,30); //Blocking
		    cm.teachSkill(1121008,30,30); //Brandish
		    cm.teachSkill(1121010,30,30); //Enrage
		    cm.teachSkill(1121001,30,30); //Monster Magnet
		    cm.teachSkill(1121006,30,30); //Rush
		    cm.teachSkill(1121002,30,30); //Stance
		    cm.teachSkill(1121000,10,10); //Maple Warrior
		    break;
		case 122:
		    cm.teachSkill(1220005,30,30); //Achilles
		    cm.teachSkill(1220010,10,10); //Advanced Charge
		    cm.teachSkill(1221009,30,30); //Blast
		    cm.teachSkill(1220006,30,30); //Blocking
		    cm.teachSkill(1221004,20,20); //Divine Charge: Mace
		    cm.teachSkill(1221003,20,20); //Holy Charge: Sword
		    cm.teachSkill(1221001,30,30); //Monster Magnet
		    cm.teachSkill(1221007,30,30); //Rush
		    cm.teachSkill(1221011,30,30); //Sanctuary
		    cm.teachSkill(1221002,30,30); //Stance
		    cm.teachSkill(1221000,10,10); //Maple Warrior
		    break;
		case 132:
		    cm.teachSkill(1320005,30,30); //Achilles
		    cm.teachSkill(1321007,10,10); //Beholder
		    cm.teachSkill(1320009,25,25); //Beholder's Buff
		    cm.teachSkill(1320008,25,25); //Beholder's Healing
		    cm.teachSkill(1320006,30,30); //Berserk
		    cm.teachSkill(1321001,30,30); //Monster Magnet
		    cm.teachSkill(1321003,30,30); //Rush
		    cm.teachSkill(1321002,30,30); //Stance
		    cm.teachSkill(1321000,10,10); //Maple Warrior
		    break;
		case 212:
		    cm.teachSkill(2121001,30,30); //Big Bang
		    cm.teachSkill(2121005,30,30); //Elquines
		    cm.teachSkill(2121003,30,30); //Fire Demon
		    cm.teachSkill(2121004,30,30); //Infinity
		    cm.teachSkill(2121002,30,30); //Mana Reflection
		    cm.teachSkill(2121007,30,30); //Meteo
		    cm.teachSkill(2121006,30,30); //Paralyze
		    cm.teachSkill(2121000,10,10); //Maple Warrior
		    break;
		case 222:
		    cm.teachSkill(2221001,30,30); //Big Bang
		    cm.teachSkill(2221007,30,30); //Blizzard
		    cm.teachSkill(2221006,30,30); //Chain Lightning
		    cm.teachSkill(2221003,30,30); //Ice Demon
		    cm.teachSkill(2221005,30,30); //Ifrit
		    cm.teachSkill(2221004,30,30); //Infinity
		    cm.teachSkill(2221002,30,30); //Mana Reflection
		    cm.teachSkill(2221000,10,10); //Maple Warrior
		    break;
		case 232:
		    cm.teachSkill(2321001, 30, 30);
		    cm.teachSkill(2321002, 30, 30);
		    cm.teachSkill(2321004, 30, 30);
		    cm.teachSkill(2321005, 30, 30);
		    cm.teachSkill(2321006, 10, 10);
		    cm.teachSkill(2321007, 30, 30);
		    cm.teachSkill(2321008, 30, 30);
		    cm.teachSkill(2321003, 30, 30);
		    cm.teachSkill(2321000, 10, 10); //Maple Warrior
		    break;
		case 312:
		    cm.teachSkill(3120005,30,30); //Bow Expert
		    cm.teachSkill(3121008,30,30); //Concentration
		    cm.teachSkill(3121003,30,30); //Dragon Pulse
		    cm.teachSkill(3121007,30,30); //Hamstring
		    cm.teachSkill(3121006,30,30); //Phoenix
		    cm.teachSkill(3121002,30,30); //Sharp Eyes
		    cm.teachSkill(3121004,30,30); //Storm Arrow
		    cm.teachSkill(3121000,10,10); //Maple Warrior
		    break;
		case 322:
		    cm.teachSkill(3221006,30,30); //Blind
		    cm.teachSkill(3220004,30,30); //Crossbow Expert
		    cm.teachSkill(3221003,30,30); //Dragon Pulse
		    cm.teachSkill(3221005,30,30); //Freezer
		    cm.teachSkill(3221001,30,30); //Piercing
		    cm.teachSkill(3221002,30,30); //Sharp Eyes
		    cm.teachSkill(3221007,30,30); //Sniping
		    cm.teachSkill(3221000,10,10); //Maple Warrior
		    break;
		case 412:
		    cm.teachSkill(4120002,30,30); //Shadow Shifter
		    cm.teachSkill(4121004,30,30); //Ninja Ambush
		    cm.teachSkill(4121008,30,30); //Ninja Storm
		    cm.teachSkill(4121003,30,30); //Taunt
		    cm.teachSkill(4121006,30,30); //Spirit Claw
		    cm.teachSkill(4121007,30,30); //Triple Throw
		    cm.teachSkill(4120005,30,30); //Venomous Star
		    cm.teachSkill(4121000,10,10); //Maple Warrior
		    break;
		case 422:
		    cm.teachSkill(4221001,30,30); //Assassinate
		    cm.teachSkill(4221007,30,30); //Boomerang Step
		    cm.teachSkill(4220002,30,30); //Shadow Shifter
		    cm.teachSkill(4221004,30,30); //Ninja Ambush
		    cm.teachSkill(4221003,30,30); //Taunt
		    cm.teachSkill(4221006,30,30); //Smokescreen
		    cm.teachSkill(4220005,30,30); //Venomous Dagger
		    cm.teachSkill(4221000,10,10); //Maple Warrior
		    break;
		case 512:
		    cm.teachSkill(5121001,30,30); //Dragon Strike
		    cm.teachSkill(5121002,30,30); //Energy Orb
		    cm.teachSkill(5121003,20,20); //Super Transformation
		    cm.teachSkill(5121004,30,30); //Demolition
		    cm.teachSkill(5121005,30,30); //Snatch
		    cm.teachSkill(5121007,30,30); //Barrage
		    cm.teachSkill(5121009,20,20); //Speed Infusion
		    cm.teachSkill(5121010,30,30); //Time Leap
		    cm.teachSkill(5121000,10,10); //Maple Warrior
		    break;
		case 522:
		    cm.teachSkill(5220001,30,30); //Elemental Boost
		    cm.teachSkill(5220002,20,20); //Wrath of the Octopi
		    cm.teachSkill(5220011,20,20); //Bullseye
		    cm.teachSkill(5221003,30,30); //Aerial Strike
		    cm.teachSkill(5221004,30,30); //Rapid Fire
		    cm.teachSkill(5221006,10,10); //Battleship
		    cm.teachSkill(5221007,30,30); //Battleship Cannon
		    cm.teachSkill(5221008,30,30); //Battleship Torpedo
		    cm.teachSkill(5221009,20,20); //Hypnotize
		    cm.teachSkill(5221000,10,10); //Maple Warrior
		    break;
		default:
		    cm.sendOk("Unavailable.");
		    break;
	    }
	    cm.dispose();*/
	} else if (selection == 2) {
	    if (cm.getPlayerStat("LVL") < 45) {
		cm.sendOk("Please be at least level 45 and find me again to acquire the skill.");
	    } else if (cm.getJob() >= 2000) {
		cm.teachSkill(20001007, 3, 0); // Maker
	    } else if (cm.getJob() >= 1000) {
		cm.teachSkill(10001007, 3, 0); // Maker
	    } else {
		cm.teachSkill(1007, 3, 0); // Maker
	    }
	    cm.sendOk("I've taught you Maker skill, please make good use of it.");
	    cm.dispose();
	} else {
	    goMap = true;
	    cm.sendNextPrev("I can teleport you to various places, take note that my powers only allow me to teleport you to the #rmain#k cities, my powers can't reach beyond the Safe areas!")
	}
    } else if (status == 2) {
	if (goMap) {
	    var selStr = "Select your destination.#b";
	    for (var i = 0; i < maps.length; i++)
		selStr += "\r\n#L" + i + "##m" + maps[i] + "# #l";

	    cm.sendSimple(selStr);
	} else {
	    /*	    switch (selection) {
		case 0:
		    if (cm.getMeso() >= 1000000) {
			if (cm.canHold(5490000)) {
			    cm.gainMeso(-1000000);
			    cm.gainItem(5490000, 1);
			} else {
			    cm.sendOk("Please check if you have sufficient inventory slot.");
			}
		    } else {
			cm.sendOk("You do not have sufficient meso.");
		    }
		    break;
		case 1:
		    if (cm.getMeso() >= 500000) {
			if (cm.canHold(5490001)) {
			    cm.gainMeso(-500000);
			    cm.gainItem(5490001, 1);
			} else {
			    cm.sendOk("Please check if you have sufficient inventory slot.");
			}
		    } else {
			cm.sendOk("You do not have sufficient meso.");
		    }
		    break;
	    }*/
	    cm.dispose();
	}
    } else if (status == 3) {
	cm.sendYesNo("So you have nothing left to do here? Do you want to go to #m" + maps[selection] + "#?");
	selectedMap = selection;

    } else if (status == 4) {
	var map = cm.getMapId();
	if ((map / 1000 == 980000 && map != 980000000) || (map / 100 == 1030008) || (map / 100 == 922010) || (map / 10 == 13003000)) {
	    cm.sendOk("Unavailable in event map.");
	} else {
	    if (cm.getPlayerStat("LVL") <= 10 && cm.getJob() == 2000) { // Aran tut stage is important....
		cm.sendOkS("#b(Saving the lost kid and regaining my memories would be more important isn't it? Let's proceed with the quest instead of skipping it)#k", 3);
	    } else {
		cm.warp(maps[selectedMap], 0);
	    }
	}
	cm.dispose();
    }
}

// 	cm.sendOk("The event is not available anymore. Please check the MapleStory homepage to verify some of information for your gift.");
